﻿#region Copyright RenGuiYou. All rights reserved.

//=====================================================
// NeatlyFrameWork
// Author:      RenGuiyou
// Feedback: 	mailto:750539605@qq.com
//=====================================================

#endregion

using System;
using PandoraEditor;
using UnityEditor;

namespace NeatlyEditor
{
    public static class CommandParam
    {
        #region Core

        private const int FALSE = 0;
        private const int TRUE = 1;

        private static string GetParam(string key)
        {
            var systemParams = System.Environment.GetCommandLineArgs();
            foreach (var t in systemParams)
            {
                if (t.StartsWith(key + ":"))
                {
                    return t.Split(':')[1];
                }
            }

            return null;
        }

        private static string Get(string key, string defaultVal = null)
        {
            return GetParam(key) ?? (defaultVal);
        }

        private static int GetInt(string key, int defaultVal)
        {
            string result = Get(key);
            return result == null ? defaultVal : int.Parse(result);
        }

        private static bool GetBool(string key, bool defaultVal)
        {
            return GetInt(key, defaultVal ? TRUE : FALSE) == TRUE;
        }

        #endregion

        #region Property

        private const string company_name = "company";
        private const string product_name = "name";
        private const string icon = "icon";
        private const string bundle_identifier = "id";
        private const string version = "version";
        private const string patch_code = "patch";
        private const string symbols = "symbols";
        private const string develop = "develop";
        private const string console = "console";
        private const string aab = "aab";
        private const string dis = "dis";
        private const string server = "server";

        #endregion

        public static string CompanyName => Get(company_name, BuildSetting.ProjectBuildSetting.company_name);
        public static string ProductName => Get(product_name, BuildSetting.ProjectBuildSetting.product_name);
        public static string Icon => Get(icon, "icon");
        public static string BundleIdentifier => Get(bundle_identifier, BuildSetting.ProjectBuildSetting.bundle_identifier);
        public static string Version => Get(version, BuildSetting.ProjectBuildSetting.version);
        public static int PatchCode => GetInt(patch_code, int.Parse(DateTime.Now.ToString("MMddHHmmss")));
        public static string Symbols => Get(symbols, BuildSetting.ProjectBuildSetting.symbols);
        public static bool Develop => GetBool(develop, BuildSetting.ProjectBuildSetting.is_develop);
        public static bool Console => GetBool(console, BuildSetting.ProjectBuildSetting.is_console);
        public static bool UseAab => GetBool(aab, false);
        public static bool ExportDis => GetBool(dis, false);
        public static int ServerType => GetInt(server, 1);
    }
}